home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / var / lib / dpkg / info / rsyslog.postinst < prev    next >
Text File  |  2009-10-15  |  3KB  |  120 lines

  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. # summary of how this script can be called:
  6. #        * <postinst> `configure' <most-recently-configured-version>
  7. #        * <old-postinst> `abort-upgrade' <new version>
  8. #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
  9. #          <new-version>
  10. #        * <postinst> `abort-remove'
  11. #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
  12. #          <failed-install-package> <version> `removing'
  13. #          <conflicting-package> <version>
  14. # for details, see http://www.debian.org/doc/debian-policy/ or
  15. # the debian-policy package
  16.  
  17. rotate_old_log_files()
  18. {
  19.     log_files="syslog mail.info mail.warn mail.err mail.log daemon.log \
  20.                kern.log auth.log user.log lpr.log cron.log debug messages"
  21.     skipped_files=""
  22.     dir=/var/log
  23.  
  24.     for f in $log_files; do
  25.         if [ -e $dir/$f.0 ]; then
  26.             rotate="yes"
  27.             if [ -e $dir/$f.1.gz ]; then
  28.                 date0=$(stat --format=%Y $dir/$f.0)
  29.                 date1=$(stat --format=%Y $dir/$f.1.gz)
  30.                 if [ $date0 -lt $date1 ] ; then
  31.                     # .0 log file is older than .1
  32.                     skipped_files="$dir/$f.0\n$skipped_files"
  33.                     rotate="no"
  34.                 fi
  35.             fi
  36.             if [ "$rotate" = "yes" ] ; then
  37.                 for s in $(seq 9 -1 1) ; do
  38.                     if [ -e $dir/$f.$s.gz ]; then
  39.                         mv $dir/$f.$s.gz $dir/$f.$(($s+1)).gz
  40.                     fi
  41.                 done
  42.                 mv $dir/$f.0 $dir/$f.1
  43.             fi
  44.         fi
  45.     done
  46.     if [ -n "$skipped_files" ]; then
  47.         printf "The following old log files were found which could not be rotated safely.\n"
  48.         printf "\n$skipped_files\n"
  49.         printf "Please inspect them manually and delete them, if no longer required.\n"
  50.     fi
  51. }
  52.  
  53.  
  54. case "$1" in
  55.     configure)
  56.     # Rotate .0 log files when migrating from sysklogd
  57.     if dpkg --compare-versions "$2" lt "3.18.5-1"; then
  58.         rotate_old_log_files
  59.     fi
  60.  
  61.     user_conf=/etc/rsyslog.d/50-default.conf
  62.     default_conf=/usr/share/rsyslog/50-default.conf
  63.  
  64.     # Upgrade handling for config file.  We copy syslog.conf if it exists and
  65.     # is modified, else use our default fresh-install config.
  66.     if dpkg --compare-versions "$2" lt "3.22.0-1ubuntu1"; then
  67.         pkg_name=sysklogd
  68.         old_conf=/etc/syslog.conf
  69.         if [ -e $old_conf ]; then
  70.             md5sum="`md5sum \"$old_conf\" | sed -e \"s/ .*//\"`"
  71.             old_md5sum="$(dpkg-query -W -f='${Conffiles}' $pkg_name | \
  72.               sed -n -e "\' $old_conf ' { s/ obsolete$//; s/.* //; p }")"
  73.             if [ "$md5sum" != "$old_md5sum" ]; then
  74.                 cp -n $old_conf $user_conf
  75.             fi
  76.         fi
  77.     fi
  78.  
  79.     ucf --three-way --debconf-ok $default_conf $user_conf
  80.     ucfr rsyslog $user_conf
  81.  
  82.     adduser --system --group --no-create-home --quiet syslog || true
  83.  
  84.     # Gross hack to stop an error when upgrading from sysklogd to rsyslog.
  85.     # sysklogd tries to 'deluser syslog' but rsyslog will be running by then.
  86.     # It was decided sysklogd should not be trying to delete the user at all.
  87.     # So we correct that mistake by sed'ing sysklogd's postrm script.
  88.     # See LP: #401056
  89.     if [ -e /var/lib/dpkg/info/sysklogd.postrm ]; then
  90.         sed -i -e '/deluser/d' /var/lib/dpkg/info/sysklogd.postrm
  91.     fi
  92.     ;;
  93.  
  94.     abort-upgrade|abort-remove|abort-deconfigure)
  95.     ;;
  96.  
  97.     *)
  98.     echo "postinst called with unknown argument \`$1'" >&2
  99.     exit 1
  100.     ;;
  101. esac
  102.  
  103.  
  104. # Automatically added by dh_installinit
  105. if [ -x "/etc/init.d/rsyslog" ]; then
  106.     if [ -n "$2" ]; then
  107.         _dh_action=restart
  108.     else
  109.         _dh_action=start
  110.     fi
  111.     invoke-rc.d rsyslog $_dh_action || exit $?
  112. fi
  113. # End automatically added section
  114. # Automatically added by dh_installinit
  115. update-rc.d -f rsyslog remove >/dev/null || exit $?
  116. # End automatically added section
  117.  
  118.  
  119. exit 0
  120.